package com.ruoyi.web.controller.ydz;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.DrugTarget;
import com.ruoyi.web.service.IDrugTargetService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品靶点关联Controller
 * 
 * @author drx
 * @date 2025-05-16
 */
@Controller
@RequestMapping("/ydz/target")
@Api(tags = "药品靶点关联")
public class DrugTargetController extends BaseController
{
    private String prefix = "ydz/target";

    @Autowired
    private IDrugTargetService drugTargetService;

    @RequiresPermissions("ydz:target:view")
    @GetMapping()
    public String target()
    {
        return prefix + "/target";
    }

    /**
     * 查询药品靶点关联列表
     */
    @RequiresPermissions("ydz:target:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询药品靶点关联列表")
    public TableDataInfo list(DrugTarget drugTarget)
    {
        startPage();
        List<DrugTarget> list = drugTargetService.selectDrugTargetList(drugTarget);
        return getDataTable(list);
    }

    /**
     * 导出药品靶点关联列表
     */
    @RequiresPermissions("ydz:target:export")
    @Log(title = "药品靶点关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出药品靶点关联列表")
    public AjaxResult export(DrugTarget drugTarget)
    {
        List<DrugTarget> list = drugTargetService.selectDrugTargetList(drugTarget);
        ExcelUtil<DrugTarget> util = new ExcelUtil<DrugTarget>(DrugTarget.class);
        return util.exportExcel(list, "药品靶点关联数据");
    }

    /**
     * 新增药品靶点关联
     */
    @GetMapping("/add")
    @ApiOperation("新增药品靶点关联")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药品靶点关联
     */
    @ApiOperation("新增保存药品靶点关联")
    @RequiresPermissions("ydz:target:add")
    @Log(title = "药品靶点关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DrugTarget drugTarget)
    {
        return toAjax(drugTargetService.insertDrugTarget(drugTarget));
    }

    /**
     * 修改药品靶点关联
     */
    @ApiOperation("修改药品靶点关联")
    @RequiresPermissions("ydz:target:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DrugTarget drugTarget = drugTargetService.selectDrugTargetById(id);
        mmap.put("drugTarget", drugTarget);
        return prefix + "/edit";
    }

    /**
     * 修改保存药品靶点关联
     */
    @ApiOperation("修改保存药品靶点关联")
    @RequiresPermissions("ydz:target:edit")
    @Log(title = "药品靶点关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DrugTarget drugTarget)
    {
        return toAjax(drugTargetService.updateDrugTarget(drugTarget));
    }

    /**
     * 删除药品靶点关联
     */
    @ApiOperation("删除药品靶点关联")
    @RequiresPermissions("ydz:target:remove")
    @Log(title = "药品靶点关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(drugTargetService.deleteDrugTargetByIds(ids));
    }
}
